View Javadoc
1 /*** 2 * Title: S/MIME Project 3 * Description: Creating S/MIME email transport capabilities. 4 * Copyright: Copyright (c) 2001 5 * @Author Vladimir Radisic 6 * @Version 2.0.1 7 */ 8 9 package org.webdocwf.util.smime.util; 10 11 12 import org.webdocwf.util.smime.exception.SMIMEException; 13 import java.io.File; 14 import java.io.FileInputStream; 15 import java.io.InputStream; 16 import java.io.IOException; 17 18 19 /*** 20 * This class contains static methods which makes easier work and conversion 21 * between different types under the large ammount of data (arrays, streams, 22 * files ...). 23 */ 24 public class ConvertAssist { 25 26 /*** 27 * Reads data from input stream into the byte array. 28 * @param in0 source of data for reading 29 * @return data extracted from input stream represented as byte array 30 * @exception SMIMEException caused by non SMIMEException which is IOException 31 */ 32 public static byte[] inStreamToByteArray(InputStream in0) throws SMIMEException { 33 34 byte[] returnArray = null; 35 36 try { 37 String sAtach = new String(); 38 byte[] b = new byte[100000]; 39 int a = in0.read(b); 40 41 while (a == 100000) { 42 sAtach = sAtach.concat(new String(b, "ISO-8859-1")); 43 a = in0.read(b); 44 } 45 in0.close(); 46 sAtach = sAtach.concat(new String(b, "ISO-8859-1").substring(0, a)); 47 48 returnArray = sAtach.getBytes("ISO-8859-1"); 49 } catch (IOException e) { 50 throw SMIMEException.getInstance("org.webdocwf.util.smime.util.ConvertAssist", 51 e, "constructor"); 52 } 53 54 return returnArray; 55 } 56 57 /*** 58 * Reads data from file into the String. 59 * @param file0 abstract path to file represented as File object 60 * @return data from file represented as String 61 * @exception SMIMEException caused by non SMIMEException which is IOException 62 */ 63 public static String readFileToString(File file0) throws SMIMEException { 64 65 String s = null; 66 67 try { 68 FileInputStream temp = new FileInputStream(file0); 69 70 s = new String(); 71 byte[] b = new byte[100000]; 72 int a = temp.read(b); 73 74 while (a == 100000) { 75 s = s.concat(new String(b, "ISO-8859-1")); 76 a = temp.read(b); 77 } 78 temp.close(); 79 s = s.concat(new String(b, "ISO-8859-1").substring(0, a)); 80 } catch (Exception e) { 81 throw SMIMEException.getInstance("org.webdocwf.util.smime.util.FileAssist", 82 e, "readFileToString"); 83 } 84 return s; 85 } 86 87 /*** 88 * Reads data from file into the byte array. 89 * @param file0 abstract path to file represented as File object 90 * @return data from file represented as byte array 91 * @exception SMIMEException caused by non SMIMEException which is IOException 92 */ 93 public static byte[] readFileToByteArray(File file0) throws SMIMEException { 94 95 try { 96 return readFileToString(file0).getBytes("ISO-8859-1"); 97 } catch (Exception e) { 98 throw SMIMEException.getInstance("org.webdocwf.util.smime.util.FileAssist", 99 e, "readFileToByteArray"); 100 } 101 } 102 103 }

This page was automatically generated by Maven